package states 
{
	import flash.geom.Point;
	import model.MSpaceship;
	import statemachine.IState;
	import statemachine.IStateObject;
	
	/**
	 * @author vkozhaev
	 */
	public class MovingState extends State implements IState
	{
		private var _delta:Point;
		
		public function MovingState(_stateObject:IStateObject,_delta:Point=null) 
		{
			super(_stateObject);	
			this._delta = _delta;
		}
		
		public override function doInProcess():void
		{
			var oldCoords:Point = (this._stateObject as MSpaceship).coords;
			var newCoords:Point = new Point(oldCoords.x + _delta.x, oldCoords.y + _delta.y);	
			(this._stateObject as MSpaceship).coords = newCoords;
		}
		
		public override function doAfter():void
		{
			var oldCoords:Point = (this._stateObject as MSpaceship).cellCoords;
			var newCoords:Point = new Point(oldCoords.x + _delta.x, oldCoords.y + _delta.y);	
			
			(this._stateObject as MSpaceship).cellCoords = newCoords;
			(this._stateObject as MSpaceship).initCoords();
			
			(this._stateObject as MSpaceship).energy--;
		}
		
		public function get delta():Point 
		{
			return _delta;
		}
		
		public function set delta(val:Point):void 
		{
			this._delta=val;
		}
		
	}

}